//src/chat/chat.controller.ts
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { ChatService } from './chat.service';
import { ApiOperation } from '@nestjs/swagger';
import { CreateChatDto } from './dto/create-chat.dto';
@Controller('chat')
export class ChatController {
  constructor(private readonly chatService: ChatService) {}

@Post('model')
@ApiOperation({
  summary: '广告合规审核对话大模型',
  description: '审核广告文本',
})
async chatModel(@Body() body) {
  try {
    const result = await this.chatService.chatModel(body.question);
    return { code: 0, data: result }; // 成功返回结构化数据
  } catch (error) {
    return { 
      code: 1,
      message: error.message || 'Internal Server Error' // 返回错误消息
    };
  }
}

  // 保存聊天记录
  @Post('save')
  async saveChat(@Body() createChatDto: CreateChatDto): Promise<any> {
    return this.chatService.saveChat(
      createChatDto.senderId,
      createChatDto.receiverId,
      createChatDto.message,
      createChatDto.links,
    );
  }

  // 查询聊天记录
  @Get(':userId/history/:targetUserId')
  async getChatHistory(
    @Param('userId') userId: string,
    @Param('targetUserId') targetUserId: string,
  ) {
    return this.chatService.getChatHistory(userId, targetUserId);
  }
}
